package org.syndicate.web;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.syndicate.domain.FacilityInvestment;

@RooWebScaffold(path = "facilityinvestments", formBackingObject = FacilityInvestment.class)
@RequestMapping("/facilityinvestments")
@Controller
public class FacilityInvestmentController {
	
	@RequestMapping(method = RequestMethod.POST)
    public String create(@Valid FacilityInvestment facilityInvestment, BindingResult result, Model model, HttpServletRequest request) {
        if (result.hasErrors()) {
            model.addAttribute("facilityInvestment", facilityInvestment);
            return "facilityinvestments/create";
        }
        //TODO create facade method!!!
        facilityInvestment.execute();
        facilityInvestment.persist();
        return "redirect:/facilityinvestments/" + encodeUrlPathSegment(facilityInvestment.getId().toString(), request);
    }
}
